package com.jumper.cwolf.leetcode;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 描述：
 *
 * @author cwolf
 * @version 1.0
 * @date 2021/4/2 11:18
 */
public class Code781 {

    public int numRabbits(int[] answers) {
        if(answers.length==0){
            return 0;
        }
        Map<Integer,Integer> sets = new HashMap<>(answers.length);
        for(Integer i:answers){
            Integer integer = sets.getOrDefault(i,0);
            integer++;
            sets.put(i,integer);
        }
        int total = 0;
        for(Integer key: sets.keySet()){
            Integer value = sets.get(key);
            if(key==0){
                total+=(value.intValue());
            }else{
                int x = key+1;
                double d = value.doubleValue() / x;
                int ceil = (int) Math.ceil(d);
                total+= (x*ceil);
            }
        }
        return total;
    }


    public static void main(String[] args) {

        int[] arr = new int[]{
                1,0,1,0,0
        };
        int i = new Code781().numRabbits(arr);
        System.out.println(i);
    }

}
